import * as Cesium from "cesium";
//流动材质
export default class LineFlowWallMaterialProperty {
    constructor(style) {
        this._definitionChanged = new Cesium.Event();
        this._color = undefined;
        this._colorSubscription = undefined;
        this.color = style.color;
        this.duration = style.duration;
        this._time = (new Date()).getTime();
    }
}
Object.defineProperties(LineFlowWallMaterialProperty.prototype, {
    isConstant: {
        get: function () {
            return false;
        }
    },
    definitionChanged: {
        get: function () {
            return this._definitionChanged;
        }
    },
    color: Cesium.createPropertyDescriptor('color')
});

LineFlowWallMaterialProperty.prototype.getType = function (time) {
    return 'LineFlowWall';
}

LineFlowWallMaterialProperty.prototype.getValue = function (time, result) {
    if (!Cesium.defined(result)) {
        result = {};
    }
    result.color = Cesium.Property.getValueOrClonedDefault(this._color, time, Cesium.Color.WHITE, result.color);
    result.image = Cesium.Material.LineFlowWallImage;
    result.time = (((new Date()).getTime() - this._time) % this.duration) / this.duration;
    return result;
}

LineFlowWallMaterialProperty.prototype.equals = function (other) {
    return this === other ||
        (other instanceof LineFlowWallMaterialProperty &&
            Cesium.Property.equals(this._color, other._color))
}
Cesium.Material.LineFlowWallType = 'LineFlowWall';
Cesium.Material.LineFlowWallImage = "";
Cesium.Material.LineFlowWallSource =
    "czm_material czm_getMaterial(czm_materialInput materialInput)\n\
 {\n\
      czm_material material = czm_getDefaultMaterial(materialInput);\n\
      vec2 st = materialInput.st;\n\
      vec4 colorImage = texture(image, vec2(fract(st.t - time), st.t));\n\
      material.alpha = colorImage.a * color.a;\n\
      material.diffuse =  1.5* color.rgb  ;\n\
      return material;\n\
  }";
Cesium.Material._materialCache.addMaterial(Cesium.Material.LineFlowWallType, {
    fabric: {
        type: Cesium.Material.LineFlowWallType,
        uniforms: {
            color: new Cesium.Color(1.0, 0.0, 0.0, 0.5),
            image: Cesium.Material.LineFlowWallImage,
            time: 0
        },
        source: Cesium.Material.LineFlowWallSource
    },
    translucent: function (material) {
        return true;
    }
});
